<?php

use plugin\enterprise\app\controller\AuthController;
use plugin\enterprise\app\controller\EnterprisePermissionController;
use plugin\enterprise\app\controller\EnterpriseUserController;
use plugin\enterprise\app\controller\HomeController;
use plugin\enterprise\app\controller\IndexController;
use plugin\enterprise\app\controller\monitor\EnterpriseLoginLogController;
use plugin\enterprise\app\controller\monitor\EnterpriseOperationLogController;
use plugin\enterprise\app\Enterprise;
use plugin\enterprise\app\controller\EnterpriseMenuController;
use plugin\enterprise\app\controller\EnterpriseRoleController;
use Webman\Route;

Route::get('/enterprise', fn() => Enterprise::view('enterprise-api'));


Route::group('/' . config('plugin.enterprise.enterprise.route.prefix'), function () {

    Route::get('/login', [AuthController::class, 'loginPage']);
    Route::post('/login', [AuthController::class, 'login']);
    Route::get('/logout', [AuthController::class, 'logout']);
    Route::get('/captcha', [AuthController::class, 'reloadCaptcha']);
    Route::get('/current-user', [AuthController::class, 'currentUser']);

    Route::get('/menus', [IndexController::class, 'menus']);
    Route::get('/_settings', [IndexController::class, 'settings']);
    Route::post('/_settings', [IndexController::class, 'saveSettings']);
    Route::get('/no-content', [IndexController::class, 'noContentResponse']);
    Route::get('/_download_export', [IndexController::class, 'downloadExport']);
    Route::get('/_iconify_search', [IndexController::class, 'iconifySearch']);
    Route::get('/page_schema', [IndexController::class, 'pageSchema']);

    Route::any('/upload_file', [IndexController::class, 'uploadFile']);
    Route::any('/upload_chunk_start', [IndexController::class, 'chunkUploadStart']);
    Route::any('/upload_chunk', [IndexController::class, 'chunkUpload']);
    Route::any('/upload_chunk_finish', [IndexController::class, 'chunkUploadFinish']);
    Route::any('/upload_rich', [IndexController::class, 'uploadRich']);
    Route::any('/upload_image', [IndexController::class, 'uploadImage']);
    Route::get('/user_setting', [AuthController::class, 'userSetting']);
    Route::put('/user_setting', [AuthController::class, 'saveUserSetting']);

    Route::resource('/dashboard', HomeController::class);

    Route::group('/system', function () {
        Route::get('/', [EnterpriseUserController::class, 'index']);

        Route::resource('/enterprise_users', EnterpriseUserController::class);

        Route::post('/enterprise_menus/save_order', [EnterpriseMenuController::class, 'saveOrder']);
        Route::resource('/enterprise_menus', EnterpriseMenuController::class);
        Route::resource('/enterprise_roles', EnterpriseRoleController::class);
        Route::resource('/enterprise_permissions', EnterprisePermissionController::class);

        Route::post('/enterprise_role_save_permissions', [EnterpriseRoleController::class, 'savePermissions']);
        Route::post('/_enterprise_permissions_auto_generate', [EnterprisePermissionController::class, 'autoGenerate']);

    });

    Route::group('/log_monitoring', function () {
        // 登录日志
        Route::resource('/enterprise_login_log', EnterpriseLoginLogController::class);
        Route::resource('/enterprise_operation_log', EnterpriseOperationLogController::class);
    });
});

